package com.lineage.william;

import com.lineage.DatabaseFactory;
import com.lineage.Server;
import com.lineage.server.model.Instance.L1MonsterInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Teleport;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.utils.L1SpawnUtil;
import com.lineage.server.utils.SQLUtil;
import com.lineage.server.world.World;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

public class Npc_Dead_span {
  private static ArrayList<ArrayList<Object>> aData17 = new ArrayList<>();
  
  private static boolean NO_MORE_GET_DATA17 = false;
  
  public static final String TOKEN = ",";
  
  public static void main(String[] a) {
    try {
      while (true)
        Server.main(null); 
    } catch (Exception exception) {
      return;
    } 
  }
  
  public static void forresolvent(L1PcInstance pc, L1MonsterInstance mob) {
    ArrayList aTempData = null;
    int[] iTemp = null;
    if (!NO_MORE_GET_DATA17) {
      NO_MORE_GET_DATA17 = true;
      getData17();
    } 
    int i = 0;
    while (i < aData17.size()) {
      aTempData = aData17.get(i);
      if (((Integer)aTempData.get(0)).intValue() == mob.getNpcId() && mob.isDead()) {
        World.get().broadcastPacketToAll((ServerBasePacket)new S_SystemMessage((String)aTempData.get(3)));
        if (((Integer)aTempData.get(1)).intValue() > 0)
          L1SpawnUtil.spawn(pc, ((Integer)aTempData.get(1)).intValue(), 0, (
              (Integer)aTempData.get(2)).intValue() * 60); 
        if (((Integer)aTempData.get(4)).intValue() > 0)
          L1Teleport.teleport(pc, ((Integer)aTempData.get(4)).intValue(), (
              (Integer)aTempData.get(5)).intValue(), (short)((Integer)aTempData.get(6)).intValue(), 5, 
              true); 
      } 
      i++;
    } 
  }
  
  private static void getData17() {
    Connection con = null;
    try {
      con = DatabaseFactory.get().getConnection();
      Statement stat = con.createStatement();
      ResultSet rset = stat.executeQuery("SELECT * FROM w_怪物死亡召唤");
      ArrayList aReturn = null;
      String sTemp = null;
      if (rset != null)
        while (rset.next()) {
          aReturn = new ArrayList();
          aReturn.add(0, new Integer(rset.getInt("死亡NPC编号")));
          aReturn.add(1, new Integer(rset.getInt("召唤NPC编号")));
          aReturn.add(2, new Integer(rset.getInt("召唤NPC时间")));
          aReturn.add(3, rset.getString("死亡NPC说话"));
          aReturn.add(4, new Integer(rset.getInt("tele_x")));
          aReturn.add(5, new Integer(rset.getInt("tele_y")));
          aReturn.add(6, new Integer(rset.getInt("tele_mapid")));
          aData17.add(aReturn);
        }  
      SQLUtil.close(rset);
      SQLUtil.close(stat);
      SQLUtil.close(con);
    } catch (Exception exception) {}
  }
}
